#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
struct Node {
  string op;
  int t;
} doors[N];
int res[32][2];
int sum[32];
int calc(int i, int x) {
  rep(j, 1, n) {
    const Node& door = doors[j];
    int y = (door.t >> i) & 1;
    if (door.op == "AND")
      x = x & y;
    else if (door.op == "OR")
      x = x | y;
    else
      x = x ^ y;
  }
  return x;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  rep(i, 1, n) cin >> doors[i].op >> doors[i].t;
  int val = 0, ans = 0;
  per(i, 29, 0) {
    int res0 = calc(i, 0);
    int res1 = calc(i, 1);
    if (val + (1 << i) <= m && res0 < res1)
      val += 1 << i, ans += 1 << i;
    else
      ans += res0 << i;
  }
  cout << ans;
  return 0;
}